<template>
  <div class="base-echart">
    <div ref="echartsDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, defineProps, withDefaults, watchEffect } from 'vue';
import { EChartsOption } from 'echarts';
import useEcharts from '../hooks/useEcharts';

const props = withDefaults(
  defineProps<{
    options: EChartsOption;
    width?: string;
    height?: string;
  }>(),
  {
    width: '100%',
    height: '360px'
  }
);

const echartsDivRef = ref<HTMLElement>();
onMounted(() => {
  const { setOptions } = useEcharts(echartsDivRef.value!);
  setOptions(props.options);

  watchEffect(() => {
    setOptions(props.options);
  });
});
</script>

<style scoped></style>
